<template>
  <div
    :class="[props.configOption.styleValue == 1 ? 'row-goods' : 'lines-goods']"
  >
    <div
      class="goods-items"
      v-for="(item, index) in props.configOption.lists"
      :key="index"
      @click="changeGoodsItem(item, index)"
    >
      <img
        src="@/assets/close.png"
        alt=""
        class="i-close"
        @click.stop="handleClose(item, index)"
      />
      <img :src="item.pic" alt="" class="pic" />
      <div class="prod-info">
        <div class="title line-2">{{ item.title }}</div>
        <div class="price">
          <div class="symbol">￥</div>
          <div class="big">{{ parsePrice(item.price)[0] }}</div>
          <div class="small">.{{ parsePrice(item.price)[1] }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, toRefs, onMounted } from "vue";
import useLowCode from "@/store/useBaseLowCode";

const parsePrice = (val) => {
  val = Number(val);
  if (!val) {
    val = 0;
  }
  return val.toFixed(2).split(".");
};

let lowCode = useLowCode();

const changeGoodsItem = (item, index) => {
  lowCode.getComponentsConfig.dataField.goodsIndex = index;
};

const handleClose = (item, index) => {
  lowCode.getComponentsConfig.dataField.lists.splice(index, 1);
};

const props = defineProps({
  configOption: {
    type: Object,
    default: () => {},
  },
});
</script>
<style scoped lang="scss">
.lines-goods {
  width: 100%;
  padding: 12px 12px 0 12px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .goods-items {
    background: #fff;
    width: 100%;
    margin-bottom: 10px;
    display: flex;
    padding: 10px 10px;
    position: relative;
    .i-close {
      width: 24px;
      height: 24px;
      position: absolute;
      right: -3px;
      top: -7px;
    }
    .pic {
      width: 100px;
      height: 80px;
      display: flex;
      flex-shrink: 0;
      border-radius: 10px;
    }
    .prod-info {
      background-color: #fff;
      padding: 0px 8px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .title {
        text-align: left;
        color: #333;
        font-size: 14px;
        font-weight: bold;
        margin-bottom: 2px;
        line-height: 16px;
      }
      .price {
        display: flex;
        align-items: center;
        color: #fe3a26;
        font-size: 12px;
        text-align: left;
        .big {
          font-size: 18px;
          font-weight: bold;
        }
        .small {
          color: #fe3a26;
          font-size: 12px;
          text-align: left;
          font-weight: bold;
        }
      }
    }
  }
}

.row-goods {
  width: 100%;
  padding: 12px 12px 0 12px;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .goods-items {
    background: #fff;
    width: 49%;
    margin-bottom: 10px;
    position: relative;
    .i-close {
      width: 24px;
      height: 24px;
      position: absolute;
      right: -3px;
      top: -7px;
    }
    .pic {
      width: 100%;
      height: 150px;
    }
    .prod-info {
      background-color: #fff;
      padding: 8px 12px;
      .title {
        text-align: left;
        color: #333;
        font-size: 14px;
        font-weight: bold;
        margin-bottom: 2px;
        line-height: 16px;
      }
      .price {
        display: flex;
        align-items: center;
        color: #fe3a26;
        font-size: 12px;
        text-align: left;
        .big {
          font-size: 18px;
          font-weight: bold;
        }
        .small {
          color: #fe3a26;
          font-size: 12px;
          text-align: left;
          font-weight: bold;
        }
      }
    }
  }
}
</style>
